local qiuxin = fk.CreateSkill{
    name = "jinhs__qiuxin",
}

Fk:loadTranslationTable{
    ["jinhs__qiuxin"] = "求心",
    [":jinhs__qiuxin"] = "出牌阶段限一次，你可以将所有手牌当一张【洞烛先机】（助战→目标+1）使用，若如此做，此牌目标角色可以弃置一张以此法获得的"..
    "<font color='red'>♥</font>牌并回复1点体力。",

    ["#jinhs__qiuxin"] = "求心：你可以将所有手牌当一张【洞烛先机】（助战→目标+1）使用",
    ["#jinhs__qiuxin_delay"] = "求心：弃置以此法获得的一张<font color='red'>♥</font>牌并回复1点体力",
    ["qiuxin_foresight_skill"] = "洞烛先机",

    ["$jinhs__qiuxin1"] = "此生所求者，顺心意尔。",
    ["$jinhs__qiuxin2"] = "羡孔丘知天命之岁，叹吾生之不达。",
}

qiuxin:addEffect("viewas",{
    anim_type = "support",
    prompt = "#jinhs__qiuxin",
    pattern = "foresight",
    mute_card = false,
    card_filter = Util.FalseFunc,
    before_use = function(self, player, use)
        use.card.extra_data = use.card.extra_data or {}
        use.card.extra_data.heg_variation = {"@zhuzhan-public", "variation_addtarget"}
    end,
    view_as = function(self, player, cards)
      local card = Fk:cloneCard("foresight")
      card:addSubcards(player:getCardIds("h"))
      card.skillName = qiuxin.name
      return card
    end,
    after_use = function (self, player, use)
        local room = player.room
        local tos = use.tos
        for _, p in ipairs(tos) do
           room:setPlayerMark(p, qiuxin.name, 1)
        end
    end,
    enabled_at_play = function(self, player)
      return player:usedSkillTimes(qiuxin.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
    end,
})

qiuxin:addEffect(fk.PreCardEffect, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(qiuxin.name) and data.use and data.use.from == player and data.card.skillName == qiuxin.name
  end,
  on_refresh = function(self, event, target, player, data)
    local card = data.card:clone()
    local c = table.simpleClone(data.card)
    for k, v in pairs(c) do
      card[k] = v
    end
    card.skill = Fk.skills["qiuxin_foresight_skill"] ---@type Skill
    data.card = card
  end,
})

qiuxin:addEffect(fk.AfterCardsMove,{
    mute = true,
    can_trigger = function (self, event, target, player, data)
        if player.dead or player:isWounded() then return end
         local cards = {}
        for _, move in ipairs(data) do
          if move.to == player and move.toArea == Card.PlayerHand and move.skillName == "qiuxin_foresight_skill" and move.moveReason == fk.ReasonDraw then
            for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).suit == Card.Heart then
               table.insert(cards, info.cardId)
            end
          end
        end
      end
       if #cards > 0 then
        event:setCostData(self, { cards = cards})
        return true
      end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if player.dead then return end
        local cards = event:getCostData(self).cards
        local card = room:askToChooseCard(player,{
            target = player,
            flag = { card_data = {{ qiuxin.name, cards }} } ,
            prompt = "#jinhs__qiuxin_delay",
            skill_name = qiuxin.name,
        })
        room:throwCard(card, qiuxin.name, player, player)
        if player:isWounded() then
        room:recover{
          who = player,
          num = 1,
        }
       end
    end,
})

return qiuxin